import {createHashRouter,Navigate} from 'react-router-dom'
import Login from '../pages/login'
import Layout from '../pages/layout'
import Home from '../pages/home'
import AccountList from '../pages/accout/list'
import AccountAdd from '../pages/accout/add'
import AccountCenter from '../pages/accout/center'
import AccountEdit from '../pages/accout/edit'
import GoodsList from '../pages/goods/list'
import GoodsAdd from '../pages/goods/add'
import GoodsType from '../pages/goods/type'
import Order from '../pages/order'
import GoodsStatistics from '../pages/statistics/goods'
import OrderStatistics from '../pages/statistics/order'
import Shop from '../pages/shop'

const routes = [
    {
        path:'/',
        element:<Navigate to="/login" />
    },
    {
        path:'/login',
        element:<Login />
    },
    // {
    //     path:'/layout',
    //     element:<Layout />,

    // }
    // 配置都是 通过 多次加载 layout 组件 配置对应的二级页面
    {
        path:'/home',
        // title原因 面包屑显示文字 key:左侧菜单的选中选和 展开项
        loader:()=> ({title:'系统首页',key: "/home"}) ,
        element:<Layout />,
        children:[
            {
                // 只加key 不加title ===>面包屑不需要显示这个层级
                // key 是为了设置选中项 不用 路由pathname 而是用 key
                // 因为pathname: '/home/'
                loader:()=> ({key: "/home"}) ,
                index:true,
                element:<Home />
            }
        ]
    },
    {
        path:'/account',
        loader:()=>({title:'账号管理',key:'/account1'}),
        element:<Layout />,
        children:[
            {
                loader:()=>({title:'账号列表',key:'/account'}),
               index:true,

                element:<AccountList />
            },
            {
                loader:()=>({title:'账号添加',key:'/account/add'}),
                path:'/account/add',
                element:<AccountAdd/>
            },
            {
                loader:()=>({title:'个人中心',key:'/account/center'}),
                path:'/account/center',
                element:<AccountCenter/>
            },
            {
                loader:()=>({title:'修改密码',key:'/account/edit'}),
                path:'/account/edit',
                element:<AccountEdit/>
            },
        ]
    },
    {
        path:'/goods',
        loader:()=>({title:'商品管理',key:'/goods1'}),
        element:<Layout />,
        children:[
            {
                loader:()=>({title:'商品列表',key:'/goods'}),
                index:true,
                element:<GoodsList/>
            },
            {
                loader:()=>({title:'商品添加',key:'/goods/add'}),
                path:'/goods/add',
                element:<GoodsAdd />
            },
            {
                loader:()=>({title:'商品分类',key:'/goods/type'}),
                path:'/goods/type',
                element:<GoodsType />
            }
        ]
    },
    {
        path:'/order',
        loader:()=>({title:'订单管理',key:'/order'}),
        element:<Layout />,
        children:[
            {
                loader:()=>({key:'/order'}),
                index:true,
                element:<Order/>
            }
        ]
    },
    {
        path:'/shop',
        loader:()=>({title:'店铺管理',key:'/shop'}),
        element:<Layout />,
        children:[
            {
                loader:()=>({key:'/shop'}),
                index:true,
                element:<Shop />
            }
        ]
    },
    
    {
        path:'/statistics',
        loader:()=>({key:'/statistics1',title:'数据统计'}),
        element:<Layout />,
        children:[
            {
                loader:()=>({title:'商品统计',key:'/statistics'}),
                index:true,
                element:<GoodsStatistics/>
            },
            {
                loader:()=>({title:'订单统计',key:'/statistics/order'}),
                path:"/statistics/order",
                element:<OrderStatistics/>
            }
        ]
    },
]



const router = createHashRouter(routes)


export default router;